﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AutoduelClient.GameClient;
using AutoduelClient.GameClient.Player;

namespace AutoduelClient.GameUI
{

    public partial class ChassesDialog : Form
    {

        // the player requesting the chassis list
        private Player player;

        public ChassesDialog()
        {
            InitializeComponent();
        }

        public ChassesDialog(Player player, object[] chassis)
        {
            InitializeComponent();

            this.player = player;
            this.chassesList.Items.AddRange(chassis);
        }

        private void ChassesDialog_Load(object sender, EventArgs e)
        {
            this.Location = new Point(this.Owner.Location.X + this.Owner.Width / 2 - this.Width / 2, 
                this.Owner.Location.Y + this.Owner.Height / 2 - this.Height / 2);
        }

        private void purchaseBtn_Click(object sender, EventArgs e)
        {
            Chassis chassis = (Chassis)chassesList.SelectedItem;

            if (chassis != null)
            {
                this.player.Credits -= chassis.CostMod * 100; // random right now
                this.Close();
            }
            else
            {
                this.Enabled = false;
                new AsyncMessageBox("You must select a chassis to purchase.", "Invalid Chassis",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation).Show(this);
            }
        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ChassesDialog_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Owner.Enabled = true;
        }
    }
}
